package com.xinke.juc.case04;

import com.xinke.juc.util.Sleeper;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author：xinke
 * @Date：2025/10/3
 * @Desc:
 */
@Slf4j
public class DeadLock01 {
    public static void main(String[] args) {
        Object A = new Object();
        Object B = new Object();
        Thread t1 = new Thread(() -> {
            synchronized (A) {
                log.info("lock A");
                Sleeper.sleep(1);
                synchronized (B) {
                    log.info("lock B");
                    log.info("操作。。。");
                }
            }
        }, "t1");
        Thread t2 = new Thread(() -> {
            synchronized (B) {
                log.info("lock B");
                Sleeper.sleep(0.5);
                synchronized (A) {
                    log.info("lock A");
                    log.info("操作。。。");
                }
            }
        }, "t2");
        t1.start();
        t2.start();
    }
}
